package cn.lger.icollege.controller;

import cn.lger.icollege.service.AdminService;
import cn.lger.icollege.service.StudentService;
import cn.lger.icollege.service.TeacherService;
import cn.lger.icollege.util.SecurityResourceUtil;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.annotation.Resource;

/**
 * Code that Changed the World
 * Pro said
 * Created by Pro on 2018-04-23.
 */
@Controller
@RequestMapping
public class ViewEngineController {

    @Resource
    private TeacherService teacherService;
    @Resource
    private StudentService studentService;
    @Resource
    private AdminService adminService;


    @GetMapping("/")
    public String getIndexView(){
        return "/qianduan.btl";
    }

    @GetMapping("/stu")
    public String getStuView(Model model){
        String username = SecurityResourceUtil.getUserDetailsUsername();
        model.addAttribute("student", studentService.findStudentByUsername(username));
        return "/stu.btl";
    }

    @GetMapping("/teacher/2")
    public String getTeacherView(Model model) {
        String username = SecurityResourceUtil.getUserDetailsUsername();
//        ObjectMapper mapper = new ObjectMapper();
        model.addAttribute("teacher", teacherService.findTeacherByUsername(username));
        return "/teacher.btl";
    }


    @GetMapping("/teacher")
    public String getTeacherView2(Model model) {
        String username = SecurityResourceUtil.getUserDetailsUsername();
        model.addAttribute("teacher", teacherService.findTeacherByUsername(username));
        return "/mr.pro_temp.btl";
    }

    @GetMapping("/admin")
    public String getAdminView(Model model) {
        String username = SecurityResourceUtil.getUserDetailsUsername();
        model.addAttribute("admin", adminService.findAdminByUsername(username));
        return "/admin.btl";
    }

}
